home *** CD-ROM | disk | FTP | other *** search
/ 10,000 Great Games / 10,000 Great Games.iso / Product / 66 / data1.cab / Source_Files / Src / Turret.cpp < prev    next >
C/C++ Source or Header  |  2000-01-16  |  3KB  |  113 lines

  1. #include "stdafx.h"
  2.  
  3. cTurret::cTurret(int _x, int _y, cProperties *_orig)
  4.         : cWeapon(_x, _y, _orig, "MOVING")
  5.     orig->get_sequence("MOVING", moving_seq);
  6.     orig->get_sequence("FIRE", fire_seq);
  7.     
  8.     orig->get_spots("FIRE", &fire_spot);
  9.  
  10.     rotation_speed = orig->params->get_fix("*ROTATION_SPEED", TURRET_ROT_SPEED);
  11.     rotation_start = orig->params->get_fix("*ROTATION_START", 0);
  12.     rotation_end = orig->params->get_fix("*ROTATION_END", 256);
  13.     fire_delay = orig->params->get_fix("*FIRE_DELAY", TURRET_FIRE_DLY) * sec;
  14.  
  15.     rotation_direction = 1;
  16. }
  17.  
  18. cTurret::~cTurret()
  19. {
  20.     // Delete internal stuff
  21.     
  22.     fire_spot->delete_list();
  23.     
  24.     // Create explosions around turret
  25.  
  26.     cEffect::make(x, y, orig, "EXPLOSIONS", 5+rnd(5), width() / 2, height() / 2);
  27. }
  28.  
  29. void cTurret::load(cParse *list)
  30. {
  31.     cWeapon::load(list);
  32.  
  33.     rotation_speed = list->get_fix("ROTATION_SPEED", rotation_speed);
  34.     rotation_start = list->get_int("ROTATION_START", rotation_start);
  35.     rotation_end = list->get_int("ROTATION_END", rotation_end);
  36.     fire_delay = list->get_fix("FIRE_DELAY", (fix)fire_delay / sec) * sec;
  37.     armor = list->get_int("ARMOR", armor);
  38.  
  39.     set_rotation_angle(rotation_start);
  40. }
  41.  
  42. void cTurret::save()
  43. {
  44.     cWeapon::save();
  45.  
  46.     save_level_fix("ROTATION_SPEED", rotation_speed);
  47.     save_level_int("ROTATION_START", rotation_start);
  48.     save_level_int("ROTATION_END", rotation_end);
  49.     save_level_fix("FIRE_DELAY", (fix)fire_delay / sec);
  50.     save_level_int("ARMOR", armor);
  51. }
  52.  
  53. int cTurret::control()
  54.     // Check explode
  55.     
  56.     if (explode)
  57.         return FALSE;
  58.     
  59.     // Move
  60.  
  61.     cWeapon::control();    
  62.     
  63.     // Set animation
  64.  
  65.     if (animation_done())
  66.         set_sequence(moving_seq, TRUE);
  67.     
  68.     // Do rotation
  69.     
  70.     set_rotation_angle(get_rotation_angle() + rotate.delta() * rotation_direction * rotation_speed);
  71.         
  72.     if (rotation_end - rotation_start < (fix)256)
  73.     {
  74.         if (rotation_direction > (fix)0 && get_rotation_angle() > rotation_end)
  75.         {
  76.             rotation_direction = -1; 
  77.             set_rotation_angle(rotation_end);
  78.         }
  79.  
  80.         if (rotation_direction < (fix)0 && get_rotation_angle() < rotation_start)
  81.         {
  82.             rotation_direction = 1;
  83.             set_rotation_angle(rotation_start);
  84.         }
  85.     }
  86.  
  87.     // Fire?
  88.     
  89.     if (!firing)
  90.     {
  91.         int rx = x + fire_spot->get_rotated_x(get_rotation_angle()),
  92.             ry = y - fire_spot->get_rotated_y(get_rotation_angle());
  93.         
  94.         new cBullet (rx, ry, get_rotation_angle(), this);
  95.         
  96.         set_sequence(fire_seq);
  97.         
  98.         new cEffect (rx, ry, orig, "FIRE EFFECT");
  99.         
  100.         firing = fire_delay;
  101.     }
  102.     
  103.     // Check if still on screen
  104.     
  105.     return !below_screen();
  106. }
  107.  
  108. void cTurret::create_editables(int select)
  109. {
  110.     new cEditableTurret(this, select);
  111. }